package server

import (
	"biliPushServer/global"
	"biliPushServer/utils"
	"fmt"
	"net/http"
)

type Upload struct {
}

// SetHash 设置文件Hash
func (Upload) SetHash(path string, fileName string) string {
	URL := fmt.Sprintf("%v/upload/hash", global.Config.Server.URL)
	fileMd5 := utils.GetFileMd5(path)
	request, _ := http.NewRequest("POST", URL, nil)
	param := request.URL.Query()
	param.Set("file_name", fileName)
	param.Set("hash", fileMd5)
	request.URL.RawQuery = param.Encode()
	response, err := http.DefaultClient.Do(request)
	if err != nil {
		return err.Error()
	}
	if response.StatusCode == 200 {
		return fileMd5
	}
	return ""
}
